package com.gongqi.base;

import com.gongqi.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;
import java.util.List;

public class BaseServiceImpl<T> implements BaseService<T>{

    @Autowired
    private BaseMapper<T> mapper;
    @Override
    public T getById(Serializable id) {
        return mapper.loadById(id);
    }

    @Override
    public List<T> getAll() {
        return mapper.loadAll();
    }

    @Override
    public void del(Serializable id) {
        mapper.remove(id);
    }
    @Override
    public void add(T t) {
        mapper.save(t);
    }

    @Override
    public void update(T t) {
       mapper.update(t);
    }

    @Override
    public PageList<T> queryPage(BaseQuery query) {
        long total = mapper.loadCount(query);
        if (total < 1 )
            return new PageList<>();
        List<T> list = mapper.loadData(query);
        return new PageList<>(total,list);
    }
}
